﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;

namespace lcs.Web.supply
{
    public partial class ListMonthSupply : System.Web.UI.Page
    {
        Maticsoft.BLL.monthSupplayPlan msm = new Maticsoft.BLL.monthSupplayPlan();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["login"] != null)
                {
                    DataSet ds = Session["login"] as DataSet;

                    int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                    int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());

                    Bind(user_id);
                }
                //Bind(11);
            }
        }

        private void Bind(int user_id)
        {
            StringBuilder str = new StringBuilder();

            str.Append(" supplyPlanUser=" + user_id);
            str.Append(" and status='1' and isGoodsQualityStatus='1' and tid is null ");//发货前质量确认（质量表tempskd 中的tid is null，tempskd中没有记录的），需要发货前质量确认isGoodsQualityStatus = 1，在本月有效计划内
            //str.Append(" and supplyDate");获取当前月

            if (!string.IsNullOrEmpty(txt_material.Text))
            {
                str.Append( " and material like '%" + txt_material.Text + "%' ");
            }
            if (!string.IsNullOrEmpty(txt_projectName.Text))
            {
                str.Append( " and projectName like '%" + txt_projectName.Text + "%' ");
            }

            DataSet ds = msm.GetList(str.ToString());
            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();

            DataSet ds_config = new lcs.BLL.configinfo().GetList("");

            this.lbl_resultDate.Text = ds_config.Tables[0].Rows[0]["ygyjs"] + "号";
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName=="lbn_confirmFrist")
            {
                string monthSupplyPlanId = e.CommandArgument.ToString();

                if (Session["login"] != null)
                {
                    DataSet ds_login = Session["login"] as DataSet;

                    int roles_id = Convert.ToInt32(ds_login.Tables[0].Rows[0]["roles_id"].ToString());
                    int user_id = Convert.ToInt32(ds_login.Tables[0].Rows[0]["user_id"].ToString());

                    string strWhere = " supplyPlanUser= " + user_id + " and monthSupplyPlanId=" + monthSupplyPlanId;

                    DataSet ds = msm.GetList(strWhere);//当前登录人Id和月计划ID

                    lcs.BLL.tempskd tm = new BLL.tempskd();//临时质量计划表

                    lcs.Model.tempskd t = new Model.tempskd();
                    t.material = ds.Tables[0].Rows[0]["material"].ToString();
                    t.monthSupplyPlanId = int.Parse(monthSupplyPlanId);
                    t.project = ds.Tables[0].Rows[0]["projectName"].ToString();
                    t.tdate = DateTime.Now;
                    t.ttype = "发货前确认";

                    if (tm.Add(t) > 0)
                    {
                        Maticsoft.Common.MessageBox.Show(this, "添加发货期质量确认成功！");

                        Bind(user_id);
                    }
                }
                

            }
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.GridView1.PageIndex = e.NewPageIndex;

            if (Session["login"] != null)
            {
                DataSet ds = Session["login"] as DataSet;

                int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());

                Bind(user_id);
            }

        }

        protected void btn_sel_Click(object sender, EventArgs e)
        {
            if (Session["login"] != null)
            {
                DataSet ds = Session["login"] as DataSet;

                int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());

                Bind(user_id);
            }
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)//判定当前的行是否属于datarow类型的行
            {
                //当鼠标放上去的时候 先保存当前行的背景颜色 并设置新的背景色
                e.Row.Attributes.Add("onmouseover", "onmouseroverop(this)");
                //当鼠标离开的时候 将背景颜色恢复成之前的颜色
                e.Row.Attributes.Add("onmouseout", "onmouseroutop(this)");
                //单击行改变行背景颜色
                e.Row.Attributes.Add("onclick", "ItemOver(this)");
            }
        }

       
    }
}